package com.wantup.demo01;

import javax.sound.midi.Soundbank;
import java.util.Random;
import java.util.concurrent.*;

/**
 * @author Zhaoluowei
 * @version 1.0
 * @date 2019/6/27 13:30
 * <p>
 * <p>
 * 线程调度
 * 延迟或者定时执行
 */
public class TestScheduledThreadPool {

    public static void main(String[] args) {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(5);

        //线程池没有关 线程会一直阻塞
        ScheduledFuture<Integer> schedule = executorService.schedule(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int num = new Random().nextInt(100);
                System.out.println(Thread.currentThread().getName() + " : " + num);
                return num;
            }
        }, 2, TimeUnit.SECONDS);

        executorService.shutdown();

    }

}
